package com.zctest.service.impl;

import com.zctest.CommonException;
import com.zctest.dao.BookRepository;
import com.zctest.entity.Book;
import com.zctest.service.BookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zhangchao
 * @version 1.0
 * @date 2019/1/7
 */
@Service
public class BookServiceImpl implements BookService {


    @Autowired
    private BookRepository bookRepository;


    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void save(Book book) {
        Logger logger = LoggerFactory.getLogger(BookServiceImpl.class);
        logger.info("进入书籍保存");

        if (book.getBookName() == null) {
            logger.error("书籍保存异常");
            throw new CommonException("书籍保存异常");
        }
        bookRepository.save(book);
        logger.info("进入书籍成功");

    }
}
